{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aab1c933",
   "metadata": {},
   "outputs": [],
   "source": [
    "import collections\n",
    "import pandas as pd\n",
    "import csv\n",
    "import os\n",
    "import math\n",
    "#import pytesseract\n",
    "from PIL import Image\n",
    "import numpy as np\n",
    "import matplotlib.pylab as plt\n",
    "from matplotlib.ticker import MultipleLocator\n",
    "from matplotlib.ticker import FormatStrFormatter\n",
    "from matplotlib.font_manager import FontProperties\n",
    "\n",
    "\"\"\"\n",
    "提前定好的三种文字样式，方便后边标注、坐标轴标签注释\n",
    "\"\"\"\n",
    "font_set = FontProperties(fname=r'C:\\windows\\fonts\\simsun.ttc',size=7)\n",
    "font_set1 = FontProperties(fname=r'C:\\windows\\fonts\\simsun.ttc',size=14,weight='bold')\n",
    "font_set2 = FontProperties(fname=r'C:\\windows\\fonts\\simsun.ttc',size=17)\n",
    "loc = \"upper right\"\n",
    "\n",
    "csv_path = r\"E:\\messageCopy\\wechat\\WeChat Files\\wxid_gszrrav1c5oh11\\FileStorage\\File\\2023-02\\12312\"\n",
    "#加框线的区域 = [\"T1-12\",\"E2-11\"]\n",
    "加框线的区域 = []\n",
    "框线颜色 = \"#00FF00\" #十六进制颜色\n",
    "\n",
    "def get_file_list(path):\n",
    "    \"\"\"\n",
    "    读取路径，如果是文件夹，遍历文件夹，返回文件夹下所有.csv文件列表\n",
    "    如果是文件，就返回长度为1的文件列表\n",
    "    \"\"\"\n",
    "    file_list = []\n",
    "    if os.path.isdir(path):\n",
    "        for root,dirs,files in os.walk(path):        \n",
    "            for file in files:            \n",
    "                if file.endswith(\"csv\"):\n",
    "                    file_list.append(os.path.join(root,file))    \n",
    "            \n",
    "    else:\n",
    "        file_list.append(path)\n",
    "    \n",
    "    return file_list\n",
    "\n",
    "\"\"\"\n",
    "pl : 群丛csv列表\n",
    "\"\"\"\n",
    "pl = get_file_list(csv_path)\n",
    "\n",
    "\n",
    "\n",
    "def add_white_edge(region,up,down):\n",
    "    \"\"\"\n",
    "    给图片上下补白边,\n",
    "    rigion :二进制文件列表\n",
    "    up、down：上下是否加白边，原图上下是有白边的，如果没有切割过，那一侧就不需要加白边\n",
    "    \"\"\"\n",
    "    inImg = region\n",
    "    bgWidth = inImg.width\n",
    "    bgHeight = inImg.height\n",
    "\n",
    "    \"\"\"\n",
    "    创建一个白色背景图片，冒号后边是类型注释，说明这个变量的类型，加不加都行\n",
    "    \"\"\"\n",
    "    if up and down: \n",
    "        \"\"\"\n",
    "        白边长度是90，如果上下都加，创建的背景图就比原来的图片高180\n",
    "        \"\"\"\n",
    "        bgImg: Image.Image = Image.new(\"RGB\", (bgWidth, bgHeight+180), (255, 255, 255))\n",
    "        bgImg.paste(inImg, (0,90))\n",
    "    elif up:\n",
    "        bgImg: Image.Image = Image.new(\"RGB\", (bgWidth, bgHeight+90), (255, 255, 255))\n",
    "        bgImg.paste(inImg, (0,0))\n",
    "    else :\n",
    "        bgImg: Image.Image = Image.new(\"RGB\", (bgWidth, bgHeight+90), (255, 255, 255))\n",
    "        bgImg.paste(inImg, (0,90))\n",
    "    return bgImg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e88eb764",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "这是各个区的重心-名称字典，通过重心可以得到这个区的名称\n",
    "\"\"\"\n",
    "sign = {(0.0, 23.572): '1a', (0.0, 70.716): '1b', (0.0, 117.86): '1c', (0.0, 165.004): '1d', (0.0, 212.148): '1e', (0.0, 259.292): '1f', (0.0, 306.436): '1g', (0.0, 353.58): '1h', (0.0, 400.724): '1i', (0.0, 447.868): '1j', (0.0, 495.012): '1k', (0.0, 542.156): '1l', (0.0, 589.3): '1m', (0.0, 636.444): '1n', (0.0, 683.588): '1o', (0.0, 730.732): '1p', (0.0, 777.876): '1q', (0.0, 825.02): '1r', (4.0, -0.0): '2a', (4.0, 47.144): '2b', (4.0, 94.288): '2c', (4.0, 141.432): '2d', (4.0, 188.576): '2e', (4.0, 235.72): '2f', (4.0, 282.864): '2g', (4.0, 330.008): '2h', (4.0, 377.152): '2i', (4.0, 424.296): '2j', (4.0, 471.44): '2k', (4.0, 518.584): '2l', (4.0, 565.728): '2m', (4.0, 612.872): '2n', (4.0, 660.016): '2o', (4.0, 707.16): '2p', (4.0, 754.304): '2q', (4.0, 801.448): '2r', (8.0, -23.572): '3a', (8.0, 23.572): '3b', (8.0, 70.716): '3c', (8.0, 117.86): '3d', (8.0, 165.004): '3e', (8.0, 212.148): '3f', (8.0, 259.292): '3g', (8.0, 306.436): '3h', (8.0, 353.58): '3i', (8.0, 400.724): '3j', (8.0, 447.868): '3k', (8.0, 495.012): '3l', (8.0, 542.156): '3m', (8.0, 589.3): '3n', (8.0, 636.444): '3o', (8.0, 683.588): '3p', (8.0, 730.732): '3q', (8.0, 777.876): '3r', (8.0, 825.02): '3s', (12.0, -47.144): '4a', (12.0, 0.0): '4b', (12.0, 47.144): '4c', (12.0, 94.288): '4d', (12.0, 141.432): '4e', (12.0, 188.576): '4f', (12.0, 235.72): '4g', (12.0, 282.864): '4h', (12.0, 330.008): '4i', (12.0, 377.152): '4j', (12.0, 424.296): '4k', (12.0, 471.44): '4l', (12.0, 518.584): '4m', (12.0, 565.728): '4n', (12.0, 612.872): '4o', (12.0, 660.016): '4p', (12.0, 707.16): '4q', (12.0, 754.304): '4r', (12.0, 801.448): '4s', (16.0, -70.716): '5a', (16.0, -23.572): '5b', (16.0, 23.572): '5c', (16.0, 70.716): '5d', (16.0, 117.86): '5e', (16.0, 165.004): '5f', (16.0, 212.148): '5g', (16.0, 259.292): '5h', (16.0, 306.436): '5i', (16.0, 353.58): '5j', (16.0, 400.724): '5k', (16.0, 447.868): '5l', (16.0, 495.012): '5m', (16.0, 542.156): '5n', (16.0, 589.3): '5o', (16.0, 636.444): '5p', (16.0, 683.588): '5q', (16.0, 730.732): '5r', (16.0, 777.876): '5s', (16.0, 825.02): '5t', (20.0, -94.288): '6a', (20.0, -47.144): '6b', (20.0, -0.0): '6c', (20.0, 47.144): '6d', (20.0, 94.288): '6e', (20.0, 141.432): '6f', (20.0, 188.576): '6g', (20.0, 235.72): '6h', (20.0, 282.864): '6i', (20.0, 330.008): '6j', (20.0, 377.152): '6k', (20.0, 424.296): '6l', (20.0, 471.44): '6m', (20.0, 518.584): '6n', (20.0, 565.728): '6o', (20.0, 612.872): '6p', (20.0, 660.016): '6q', (20.0, 707.16): '6r', (20.0, 754.304): '6s', (20.0, 801.448): '6t', (24.0, -117.86): '7a', (24.0, -70.716): '7b', (24.0, -23.572): '7c', (24.0, 23.572): '7d', (24.0, 70.716): '7e', (24.0, 117.86): '7f', (24.0, 165.004): '7g', (24.0, 212.148): '7h', (24.0, 259.292): '7i', (24.0, 306.436): '7j', (24.0, 353.58): '7k', (24.0, 400.724): '7l', (24.0, 447.868): '7m', (24.0, 495.012): '7n', (24.0, 542.156): '7o', (24.0, 589.3): '7p', (24.0, 636.444): '7q', (24.0, 683.588): '7r', (24.0, 730.732): '7s', (24.0, 777.876): '7t', (24.0, 825.02): '7u', (6.889, 90.359): '3c-3', (5.778, 70.716): '3c-2', (6.889, 43.215): '3b-3', (6.889, 137.503): '3d-3', (6.889, 184.647): '3e-3', (5.778, 165.004): '3e-2', (6.889, 145.361): '3e-1', (6.889, 98.217): '3d-1', (5.778, 117.86): '3d-2', (6.889, 231.791): '3f-3', (6.889, 192.505): '3f-1', (6.889, 278.935): '3g-3', (5.778, 259.292): '3g-2', (6.889, 239.649): '3g-1', (5.778, 306.436): '3h-2', (5.778, 353.58): '3i-2', (6.889, 286.793): '3h-1', (6.889, 326.079): '3h-3', (5.778, 400.724): '3j-2', (6.889, 333.937): '3i-1', (6.889, 373.223): '3i-3', (5.778, 447.868): '3k-2', (6.889, 381.081): '3j-1', (6.889, 420.367): '3j-3', (6.889, 514.655): '3l-3', (5.778, 495.012): '3l-2', (6.889, 428.225): '3k-1', (6.889, 467.511): '3k-3', (6.889, 561.799): '3m-3', (5.778, 542.156): '3m-2', (6.889, 522.513): '3m-1', (6.889, 608.943): '3n-3', (5.778, 589.3): '3n-2', (6.889, 656.087): '3o-3', (5.778, 636.444): '3o-2', (6.889, 703.231): '3p-3', (5.778, 683.588): '3p-2', (6.889, 750.375): '3q-3', (5.778, 730.732): '3q-2', (6.889, 797.519): '3r-3', (5.778, 777.876): '3r-2', (6.889, 758.233): '3r-1', (6.889, 805.377): '3s-1', (10.889, 66.787): '4c-3', (10.889, 161.075): '4e-3', (10.889, 74.645): '4d-1', (10.889, 113.931): '4d-3', (10.889, 208.219): '4f-3', (10.889, 168.933): '4f-1', (10.889, 121.789): '4e-1', (10.889, 255.363): '4g-3', (10.889, 216.077): '4g-1', (10.889, 302.507): '4h-3', (10.889, 263.221): '4h-1', (10.889, 310.365): '4i-1', (10.889, 349.651): '4i-3', (10.889, 357.509): '4j-1', (10.889, 396.795): '4j-3', (10.889, 404.653): '4k-1', (10.889, 443.939): '4k-3', (10.889, 538.227): '4m-3', (10.889, 498.941): '4m-1', (10.889, 585.371): '4n-3', (10.889, 632.515): '4o-3', (10.889, 679.659): '4p-3', (10.889, 726.803): '4q-3', (10.889, 773.947): '4r-3', (10.889, 734.661): '4r-1', (10.889, 781.805): '4s-1', (14.889, -43.215): '5b-1', (14.889, 90.359): '5d-3', (14.889, 43.215): '5c-3', (14.889, 137.503): '5e-3', (14.889, 184.647): '5f-3', (14.889, 145.361): '5f-1', (14.889, 98.217): '5e-1', (14.889, 231.791): '5g-3', (14.889, 192.505): '5g-1', (14.889, 278.935): '5h-3', (14.889, 239.649): '5h-1', (14.889, 286.793): '5i-1', (14.889, 326.079): '5i-3', (14.889, 333.937): '5j-1', (14.889, 373.223): '5j-3', (14.889, 381.081): '5k-1', (14.889, 420.367): '5k-3', (14.889, 514.655): '5m-3', (14.889, 428.225): '5l-1', (14.889, 467.511): '5l-3', (14.889, 561.799): '5n-3', (14.889, 522.513): '5n-1', (14.889, 608.943): '5o-3', (14.889, 656.087): '5p-3', (14.889, 703.231): '5q-3', (14.889, 750.375): '5r-3', (14.889, 797.519): '5s-3', (14.889, 758.233): '5s-1', (14.889, 805.377): '5t-1', (18.889, -66.787): '6b-1', (18.889, 66.787): '6d-3', (18.889, 161.075): '6f-3', (17.778, 141.432): '6f-2', (18.889, 74.645): '6e-1', (17.778, 94.288): '6e-2', (18.889, 113.931): '6e-3', (18.889, 208.219): '6g-3', (18.889, 168.933): '6g-1', (18.889, 121.789): '6f-1', (18.889, 255.363): '6h-3', (18.889, 216.077): '6h-1', (18.889, 302.507): '6i-3', (17.778, 282.864): '6i-2', (18.889, 263.221): '6i-1', (17.778, 330.008): '6j-2', (17.778, 377.152): '6k-2', (18.889, 310.365): '6j-1', (18.889, 349.651): '6j-3', (17.778, 424.296): '6l-2', (18.889, 357.509): '6k-1', (18.889, 396.795): '6k-3', (17.778, 471.44): '6m-2', (18.889, 404.653): '6l-1', (18.889, 443.939): '6l-3', (18.889, 538.227): '6n-3', (17.778, 518.584): '6n-2', (18.889, 498.941): '6n-1', (18.889, 585.371): '6o-3', (17.778, 565.728): '6o-2', (18.889, 632.515): '6p-3', (17.778, 612.872): '6p-2', (18.889, 679.659): '6q-3', (17.778, 660.016): '6q-2', (18.889, 726.803): '6r-3', (17.778, 707.16): '6r-2', (18.889, 773.947): '6s-3', (17.778, 754.304): '6s-2', (18.889, 734.661): '6s-1', (17.778, 801.448): '6t-2', (18.889, 781.805): '6t-1', (22.889, -43.215): '7c-1', (22.889, -90.359): '7b-1', (21.778, -70.716): '7b-2', (22.889, 90.359): '7e-3', (21.778, 70.716): '7e-2', (22.889, 43.215): '7d-3', (22.889, 137.503): '7f-3', (22.889, 184.647): '7g-3', (21.778, 165.004): '7g-2', (22.889, 145.361): '7g-1', (22.889, 98.217): '7f-1', (21.778, 117.86): '7f-2', (22.889, 231.791): '7h-3', (22.889, 192.505): '7h-1', (22.889, 278.935): '7i-3', (21.778, 259.292): '7i-2', (22.889, 239.649): '7i-1', (21.778, 306.436): '7j-2', (21.778, 353.58): '7k-2', (22.889, 286.793): '7j-1', (22.889, 326.079): '7j-3', (21.778, 400.724): '7l-2', (22.889, 333.937): '7k-1', (22.889, 373.223): '7k-3', (21.778, 447.868): '7m-2', (22.889, 381.081): '7l-1', (22.889, 420.367): '7l-3', (22.889, 514.655): '7n-3', (21.778, 495.012): '7n-2', (22.889, 428.225): '7m-1', (22.889, 467.511): '7m-3', (22.889, 561.799): '7o-3', (21.778, 542.156): '7o-2', (22.889, 522.513): '7o-1', (22.889, 608.943): '7p-3', (21.778, 589.3): '7p-2', (22.889, 656.087): '7q-3', (21.778, 636.444): '7q-2', (22.889, 703.231): '7r-3', (21.778, 683.588): '7r-2', (22.889, 750.375): '7s-3', (21.778, 730.732): '7s-2', (22.889, 797.519): '7t-3', (21.778, 777.876): '7t-2', (22.889, 758.233): '7t-1', (22.889, 805.377): '7u-1', (2.889, 66.787): '2b-3', (1.778, 47.144): '2b-2', (2.889, 27.501): '2b-1', (2.889, 19.643): '2a-2', (2.889, 113.931): '2c-3', (1.778, 94.288): '2c-2', (2.889, 74.645): '2c-1', (2.889, 161.075): '2d-3', (1.778, 141.432): '2d-2', (2.889, 121.789): '2d-1', (2.889, 208.219): '2e-3', (1.778, 188.576): '2e-2', (2.889, 168.933): '2e-1', (2.889, 255.363): '2f-3', (1.778, 235.72): '2f-2', (2.889, 216.077): '2f-1', (2.889, 302.507): '2g-3', (1.778, 282.864): '2g-2', (2.889, 263.221): '2g-1', (2.889, 349.651): '2h-3', (1.778, 330.008): '2h-2', (2.889, 310.365): '2h-1', (2.889, 396.795): '2i-3', (1.778, 377.152): '2i-2', (2.889, 357.509): '2i-1', (2.889, 443.939): '2j-3', (1.778, 424.296): '2j-2', (2.889, 404.653): '2j-1', (2.889, 491.083): '2k-3', (1.778, 471.44): '2k-2', (2.889, 451.797): '2k-1', (2.889, 538.227): '2l-3', (1.778, 518.584): '2l-2', (2.889, 498.941): '2l-1', (2.889, 585.371): '2m-3', (1.778, 565.728): '2m-2', (2.889, 546.085): '2m-1', (2.889, 632.515): '2n-3', (1.778, 612.872): '2n-2', (2.889, 593.229): '2n-1', (2.889, 679.659): '2o-3', (1.778, 660.016): '2o-2', (2.889, 640.373): '2o-1', (2.889, 726.803): '2p-3', (1.778, 707.16): '2p-2', (2.889, 687.517): '2p-1', (2.889, 773.947): '2q-3', (1.778, 754.304): '2q-2', (2.889, 734.661): '2q-1', (1.778, 801.448): '2r-2', (2.889, 781.805): '2r-1', (5.778, 23.572): '3b-2', (5.778, -23.572): '3a-1', (6.889, 51.073): '3c-1', (5.778, 212.148): '3f-2', (6.889, 475.369): '3l-1', (6.889, 569.657): '3n-1', (6.889, 616.801): '3o-1', (6.889, 663.945): '3p-1', (6.889, 711.089): '3q-1', (10.889, 19.643): '4b-3', (10.889, -19.643): '4b-1', (9.778, -47.144): '4a-1', (10.889, -27.501): '4a-2', (9.778, 47.144): '4c-2', (10.889, 27.501): '4c-1', (9.778, 94.288): '4d-2', (9.778, 141.432): '4e-2', (9.778, 188.576): '4f-2', (9.778, 235.72): '4g-2', (9.778, 282.864): '4h-2', (9.778, 330.008): '4i-2', (9.778, 377.152): '4j-2', (9.778, 424.296): '4k-2', (10.889, 491.083): '4l-3', (9.778, 471.44): '4l-2', (10.889, 451.797): '4l-1', (9.778, 518.584): '4m-2', (9.778, 565.728): '4n-2', (10.889, 546.085): '4n-1', (9.778, 612.872): '4o-2', (10.889, 593.229): '4o-1', (9.778, 660.016): '4p-2', (10.889, 640.373): '4p-1', (9.778, 707.16): '4q-2', (10.889, 687.517): '4q-1', (9.778, 754.304): '4r-2', (9.778, 801.448): '4s-2', (13.778, -23.572): '5b-2', (13.778, -70.716): '5a-1', (14.889, -51.073): '5a-2', (13.778, 23.572): '5c-2', (13.778, 70.716): '5d-2', (14.889, 51.073): '5d-1', (13.778, 117.86): '5e-2', (13.778, 165.004): '5f-2', (13.778, 212.148): '5g-2', (13.778, 259.292): '5h-2', (13.778, 306.436): '5i-2', (13.778, 353.58): '5j-2', (13.778, 400.724): '5k-2', (13.778, 447.868): '5l-2', (13.778, 495.012): '5m-2', (14.889, 475.369): '5m-1', (13.778, 542.156): '5n-2', (13.778, 589.3): '5o-2', (14.889, 569.657): '5o-1', (13.778, 636.444): '5p-2', (14.889, 616.801): '5p-1', (13.778, 683.588): '5q-2', (14.889, 663.945): '5q-1', (13.778, 730.732): '5r-2', (14.889, 711.089): '5r-1', (13.778, 777.876): '5s-2', (18.889, -27.501): '6b-3', (17.778, -47.144): '6b-2', (17.778, -94.288): '6a-1', (18.889, -74.645): '6a-2', (18.889, 19.643): '6c-3', (18.889, -19.643): '6c-1', (17.778, 47.144): '6d-2', (18.889, 27.501): '6d-1', (17.778, 188.576): '6g-2', (17.778, 235.72): '6h-2', (18.889, 491.083): '6m-3', (18.889, 451.797): '6m-1', (18.889, 546.085): '6o-1', (18.889, 593.229): '6p-1', (18.889, 640.373): '6q-1', (18.889, 687.517): '6r-1', (22.889, -51.073): '7b-3', (21.778, -117.86): '7a-1', (22.889, -98.217): '7a-2', (21.778, -23.572): '7c-2', (21.778, 23.572): '7d-2', (22.889, 51.073): '7e-1', (21.778, 212.148): '7h-2', (22.889, 475.369): '7n-1', (22.889, 569.657): '7p-1', (22.889, 616.801): '7q-1', (22.889, 663.945): '7r-1', (22.889, 711.089): '7s-1', (1.111, 90.359): '1b-1', (2.222, 70.716): '1b-2', (1.111, 51.073): '1b-3', (1.111, 137.503): '1c-1', (2.222, 117.86): '1c-2', (1.111, 98.217): '1c-3', (1.111, 184.647): '1d-1', (2.222, 165.004): '1d-2', (1.111, 145.361): '1d-3', (1.111, 231.791): '1e-1', (2.222, 212.148): '1e-2', (1.111, 192.505): '1e-3', (1.111, 278.935): '1f-1', (2.222, 259.292): '1f-2', (1.111, 239.649): '1f-3', (1.111, 326.079): '1g-1', (2.222, 306.436): '1g-2', (1.111, 286.793): '1g-3', (1.111, 373.223): '1h-1', (2.222, 353.58): '1h-2', (1.111, 333.937): '1h-3', (1.111, 420.367): '1i-1', (2.222, 400.724): '1i-2', (1.111, 381.081): '1i-3', (1.111, 467.511): '1j-1', (2.222, 447.868): '1j-2', (1.111, 428.225): '1j-3', (1.111, 514.655): '1k-1', (2.222, 495.012): '1k-2', (1.111, 475.369): '1k-3', (1.111, 561.799): '1l-1', (2.222, 542.156): '1l-2', (1.111, 522.513): '1l-3', (1.111, 608.943): '1m-1', (2.222, 589.3): '1m-2', (1.111, 569.657): '1m-3', (1.111, 656.087): '1n-1', (2.222, 636.444): '1n-2', (1.111, 616.801): '1n-3', (1.111, 703.231): '1o-1', (2.222, 683.588): '1o-2', (1.111, 663.945): '1o-3', (1.111, 750.375): '1p-1', (2.222, 730.732): '1p-2', (1.111, 711.089): '1p-3', (1.111, 797.519): '1q-1', (2.222, 777.876): '1q-2', (1.111, 758.233): '1q-3', (1.111, 805.377): '1r-1', (5.111, 66.787): '2b-4', (6.222, 47.144): '2b-5', (5.111, 27.501): '2b-6', (1.778, 0.0): '2a-1', (5.111, 113.931): '2c-4', (6.222, 94.288): '2c-5', (5.111, 74.645): '2c-6', (5.111, 161.075): '2d-4', (6.222, 141.432): '2d-5', (5.111, 121.789): '2d-6', (5.111, 208.219): '2e-4', (6.222, 188.576): '2e-5', (5.111, 168.933): '2e-6', (5.111, 255.363): '2f-4', (6.222, 235.72): '2f-5', (5.111, 216.077): '2f-6', (5.111, 302.507): '2g-4', (6.222, 282.864): '2g-5', (5.111, 263.221): '2g-6', (5.111, 349.651): '2h-4', (6.222, 330.008): '2h-5', (5.111, 310.365): '2h-6', (5.111, 396.795): '2i-4', (6.222, 377.152): '2i-5', (5.111, 357.509): '2i-6', (5.111, 443.939): '2j-4', (6.222, 424.296): '2j-5', (5.111, 404.653): '2j-6', (5.111, 491.083): '2k-4', (6.222, 471.44): '2k-5', (5.111, 451.797): '2k-6', (5.111, 538.227): '2l-4', (6.222, 518.584): '2l-5', (5.111, 498.941): '2l-6', (5.111, 585.371): '2m-4', (6.222, 565.728): '2m-5', (5.111, 546.085): '2m-6', (5.111, 632.515): '2n-4', (6.222, 612.872): '2n-5', (5.111, 593.229): '2n-6', (5.111, 679.659): '2o-4', (6.222, 660.016): '2o-5', (5.111, 640.373): '2o-6', (5.111, 726.803): '2p-4', (6.222, 707.16): '2p-5', (5.111, 687.517): '2p-6', (5.111, 773.947): '2q-4', (6.222, 754.304): '2q-5', (5.111, 734.661): '2q-6', (6.222, 801.448): '2r-3', (5.111, 781.805): '2r-4', (9.111, 43.215): '3b-4', (10.222, 23.572): '3b-5', (9.111, 3.929): '3b-6', (6.889, -3.929): '3a-2', (9.111, 90.359): '3c-4', (10.222, 70.716): '3c-5', (9.111, 51.073): '3c-6', (6.889, 3.929): '3b-1', (9.111, 137.503): '3d-4', (10.222, 117.86): '3d-5', (9.111, 98.217): '3d-6', (9.111, 184.647): '3e-4', (10.222, 165.004): '3e-5', (9.111, 145.361): '3e-6', (9.111, 231.791): '3f-4', (10.222, 212.148): '3f-5', (9.111, 192.505): '3f-6', (9.111, 278.935): '3g-4', (10.222, 259.292): '3g-5', (9.111, 239.649): '3g-6', (9.111, 326.079): '3h-4', (10.222, 306.436): '3h-5', (9.111, 286.793): '3h-6', (9.111, 373.223): '3i-4', (10.222, 353.58): '3i-5', (9.111, 333.937): '3i-6', (9.111, 420.367): '3j-4', (10.222, 400.724): '3j-5', (9.111, 381.081): '3j-6', (9.111, 467.511): '3k-4', (10.222, 447.868): '3k-5', (9.111, 428.225): '3k-6', (9.111, 514.655): '3l-4', (10.222, 495.012): '3l-5', (9.111, 475.369): '3l-6', (9.111, 561.799): '3m-4', (10.222, 542.156): '3m-5', (9.111, 522.513): '3m-6', (9.111, 608.943): '3n-4', (10.222, 589.3): '3n-5', (9.111, 569.657): '3n-6', (9.111, 656.087): '3o-4', (10.222, 636.444): '3o-5', (9.111, 616.801): '3o-6', (9.111, 703.231): '3p-4', (10.222, 683.588): '3p-5', (9.111, 663.945): '3p-6', (9.111, 750.375): '3q-4', (10.222, 730.732): '3q-5', (9.111, 711.089): '3q-6', (9.111, 797.519): '3r-4', (10.222, 777.876): '3r-5', (9.111, 758.233): '3r-6', (9.111, 805.377): '3s-2', (13.111, 19.643): '4b-4', (14.222, 0.0): '4b-5', (13.111, -19.643): '4b-6', (13.111, 66.787): '4c-4', (14.222, 47.144): '4c-5', (13.111, 27.501): '4c-6', (9.778, 0.0): '4b-2', (13.111, 113.931): '4d-4', (14.222, 94.288): '4d-5', (13.111, 74.645): '4d-6', (13.111, 161.075): '4e-4', (14.222, 141.432): '4e-5', (13.111, 121.789): '4e-6', (13.111, 208.219): '4f-4', (14.222, 188.576): '4f-5', (13.111, 168.933): '4f-6', (13.111, 255.363): '4g-4', (14.222, 235.72): '4g-5', (13.111, 216.077): '4g-6', (13.111, 302.507): '4h-4', (14.222, 282.864): '4h-5', (13.111, 263.221): '4h-6', (13.111, 349.651): '4i-4', (14.222, 330.008): '4i-5', (13.111, 310.365): '4i-6', (13.111, 396.795): '4j-4', (14.222, 377.152): '4j-5', (13.111, 357.509): '4j-6', (13.111, 443.939): '4k-4', (14.222, 424.296): '4k-5', (13.111, 404.653): '4k-6', (13.111, 491.083): '4l-4', (14.222, 471.44): '4l-5', (13.111, 451.797): '4l-6', (13.111, 538.227): '4m-4', (14.222, 518.584): '4m-5', (13.111, 498.941): '4m-6', (13.111, 585.371): '4n-4', (14.222, 565.728): '4n-5', (13.111, 546.085): '4n-6', (13.111, 632.515): '4o-4', (14.222, 612.872): '4o-5', (13.111, 593.229): '4o-6', (13.111, 679.659): '4p-4', (14.222, 660.016): '4p-5', (13.111, 640.373): '4p-6', (13.111, 726.803): '4q-4', (14.222, 707.16): '4q-5', (13.111, 687.517): '4q-6', (13.111, 773.947): '4r-4', (14.222, 754.304): '4r-5', (13.111, 734.661): '4r-6', (14.222, 801.448): '4s-3', (13.111, 781.805): '4s-4', (17.111, -3.929): '5b-4', (18.222, -23.572): '5b-5', (17.111, -43.215): '5b-6', (17.111, 43.215): '5c-4', (18.222, 23.572): '5c-5', (17.111, 3.929): '5c-6', (14.889, -3.929): '5b-3', (17.111, 90.359): '5d-4', (18.222, 70.716): '5d-5', (17.111, 51.073): '5d-6', (14.889, 3.929): '5c-1', (17.111, 137.503): '5e-4', (18.222, 117.86): '5e-5', (17.111, 98.217): '5e-6', (17.111, 184.647): '5f-4', (18.222, 165.004): '5f-5', (17.111, 145.361): '5f-6', (17.111, 231.791): '5g-4', (18.222, 212.148): '5g-5', (17.111, 192.505): '5g-6', (17.111, 278.935): '5h-4', (18.222, 259.292): '5h-5', (17.111, 239.649): '5h-6', (17.111, 326.079): '5i-4', (18.222, 306.436): '5i-5', (17.111, 286.793): '5i-6', (17.111, 373.223): '5j-4', (18.222, 353.58): '5j-5', (17.111, 333.937): '5j-6', (17.111, 420.367): '5k-4', (18.222, 400.724): '5k-5', (17.111, 381.081): '5k-6', (17.111, 467.511): '5l-4', (18.222, 447.868): '5l-5', (17.111, 428.225): '5l-6', (17.111, 514.655): '5m-4', (18.222, 495.012): '5m-5', (17.111, 475.369): '5m-6', (17.111, 561.799): '5n-4', (18.222, 542.156): '5n-5', (17.111, 522.513): '5n-6', (17.111, 608.943): '5o-4', (18.222, 589.3): '5o-5', (17.111, 569.657): '5o-6', (17.111, 656.087): '5p-4', (18.222, 636.444): '5p-5', (17.111, 616.801): '5p-6', (17.111, 703.231): '5q-4', (18.222, 683.588): '5q-5', (17.111, 663.945): '5q-6', (17.111, 750.375): '5r-4', (18.222, 730.732): '5r-5', (17.111, 711.089): '5r-6', (17.111, 797.519): '5s-4', (18.222, 777.876): '5s-5', (17.111, 758.233): '5s-6', (17.111, 805.377): '5t-2', (21.111, -27.501): '6b-4', (22.222, -47.144): '6b-5', (21.111, -66.787): '6b-6', (21.111, 19.643): '6c-4', (22.222, 0.0): '6c-5', (21.111, -19.643): '6c-6', (21.111, 66.787): '6d-4', (22.222, 47.144): '6d-5', (21.111, 27.501): '6d-6', (17.778, 0.0): '6c-2', (21.111, 113.931): '6e-4', (22.222, 94.288): '6e-5', (21.111, 74.645): '6e-6', (21.111, 161.075): '6f-4', (22.222, 141.432): '6f-5', (21.111, 121.789): '6f-6', (21.111, 208.219): '6g-4', (22.222, 188.576): '6g-5', (21.111, 168.933): '6g-6', (21.111, 255.363): '6h-4', (22.222, 235.72): '6h-5', (21.111, 216.077): '6h-6', (21.111, 302.507): '6i-4', (22.222, 282.864): '6i-5', (21.111, 263.221): '6i-6', (21.111, 349.651): '6j-4', (22.222, 330.008): '6j-5', (21.111, 310.365): '6j-6', (21.111, 396.795): '6k-4', (22.222, 377.152): '6k-5', (21.111, 357.509): '6k-6', (21.111, 443.939): '6l-4', (22.222, 424.296): '6l-5', (21.111, 404.653): '6l-6', (21.111, 491.083): '6m-4', (22.222, 471.44): '6m-5', (21.111, 451.797): '6m-6', (21.111, 538.227): '6n-4', (22.222, 518.584): '6n-5', (21.111, 498.941): '6n-6', (21.111, 585.371): '6o-4', (22.222, 565.728): '6o-5', (21.111, 546.085): '6o-6', (21.111, 632.515): '6p-4', (22.222, 612.872): '6p-5', (21.111, 593.229): '6p-6', (21.111, 679.659): '6q-4', (22.222, 660.016): '6q-5', (21.111, 640.373): '6q-6', (21.111, 726.803): '6r-4', (22.222, 707.16): '6r-5', (21.111, 687.517): '6r-6', (21.111, 773.947): '6s-4', (22.222, 754.304): '6s-5', (21.111, 734.661): '6s-6', (22.222, 801.448): '6t-3', (21.111, 781.805): '6t-4', (25.111, -51.073): '7b-4', (26.222, -70.716): '7b-5', (25.111, -90.359): '7b-6', (25.111, -3.929): '7c-4', (26.222, -23.572): '7c-5', (25.111, -43.215): '7c-6', (25.111, 43.215): '7d-4', (26.222, 23.572): '7d-5', (25.111, 3.929): '7d-6', (22.889, -3.929): '7c-3', (25.111, 90.359): '7e-4', (26.222, 70.716): '7e-5', (25.111, 51.073): '7e-6', (22.889, 3.929): '7d-1', (25.111, 137.503): '7f-4', (26.222, 117.86): '7f-5', (25.111, 98.217): '7f-6', (25.111, 184.647): '7g-4', (26.222, 165.004): '7g-5', (25.111, 145.361): '7g-6', (25.111, 231.791): '7h-4', (26.222, 212.148): '7h-5', (25.111, 192.505): '7h-6', (25.111, 278.935): '7i-4', (26.222, 259.292): '7i-5', (25.111, 239.649): '7i-6', (25.111, 326.079): '7j-4', (26.222, 306.436): '7j-5', (25.111, 286.793): '7j-6', (25.111, 373.223): '7k-4', (26.222, 353.58): '7k-5', (25.111, 333.937): '7k-6', (25.111, 420.367): '7l-4', (26.222, 400.724): '7l-5', (25.111, 381.081): '7l-6', (25.111, 467.511): '7m-4', (26.222, 447.868): '7m-5', (25.111, 428.225): '7m-6', (25.111, 514.655): '7n-4', (26.222, 495.012): '7n-5', (25.111, 475.369): '7n-6', (25.111, 561.799): '7o-4', (26.222, 542.156): '7o-5', (25.111, 522.513): '7o-6', (25.111, 608.943): '7p-4', (26.222, 589.3): '7p-5', (25.111, 569.657): '7p-6', (25.111, 656.087): '7q-4', (26.222, 636.444): '7q-5', (25.111, 616.801): '7q-6', (25.111, 703.231): '7r-4', (26.222, 683.588): '7r-5', (25.111, 663.945): '7r-6', (25.111, 750.375): '7s-4', (26.222, 730.732): '7s-5', (25.111, 711.089): '7s-6', (25.111, 797.519): '7t-4', (26.222, 777.876): '7t-5', (25.111, 758.233): '7t-6', (25.111, 805.377): '7u-2', (1.111, 3.929): '1a-3', (2.222, 23.572): '1a-2', (1.111, 43.215): '1a-1', (5.111, -19.643): '2a-5', (6.222, 0.0): '2a-4', (5.111, 19.643): '2a-3', (9.111, -43.215): '3a-5', (10.222, -23.572): '3a-4', (9.111, -3.929): '3a-3', (13.111, -66.787): '4a-5', (14.222, -47.144): '4a-4', (13.111, -27.501): '4a-3', (17.111, -90.359): '5a-5', (18.222, -70.716): '5a-4', (17.111, -51.073): '5a-3', (21.111, -113.931): '6a-5', (22.222, -94.288): '6a-4', (21.111, -74.645): '6a-3', (25.111, -137.503): '7a-5', (26.222, -117.86): '7a-4', (25.111, -98.217): '7a-3', (1.111, -3.929): '1-0', (5.111, -27.501): '2-0', (9.111, -51.073): '3-0', (13.111, -74.645): '4-0', (17.111, -98.217): '5-0', (21.111, -121.789): '6-0', (25.111, -145.361): '7-0', (29.111, -168.933): '8-0', (29.778, -165.004): '9-1', (29.778, -117.86): '9-2', (29.778, -70.716): '9-3', (29.778, -23.572): '9-4', (29.778, 23.572): '9-5', (29.778, 70.716): '9-6', (29.778, 117.86): '9-7', (29.778, 165.004): '9-8', (29.778, 212.148): '9-9', (29.778, 259.292): '9-10', (29.778, 306.436): '9-11', (29.778, 353.58): '9-12', (29.778, 400.724): '9-13', (29.778, 447.868): '9-14', (29.778, 495.012): '9-15', (29.778, 542.156): '9-16', (29.778, 589.3): '9-17', (29.778, 636.444): '9-18', (29.778, 683.588): '9-19', (29.778, 730.732): '9-20', (29.778, 777.876): '9-21', (28.0, -141.432): '8a', (25.778, -141.432): '8a-1', (26.889, -121.789): '8a-2', (29.111, -121.789): '8a-3', (29.111, -161.075): '8a-4', (28.0, -94.288): '8b', (26.889, -113.931): '8b-1', (25.778, -94.288): '8b-2', (26.889, -74.645): '8b-3', (29.111, -74.645): '8b-4', (29.111, -113.931): '8b-5', (28.0, -47.144): '8c', (26.889, -66.787): '8c-1', (25.778, -47.144): '8c-2', (26.889, -27.501): '8c-3', (29.111, -27.501): '8c-4', (29.111, -66.787): '8c-5', (28.0, 0.0): '8d', (26.889, -19.643): '8d-1', (25.778, 0.0): '8d-2', (26.889, 19.643): '8d-3', (29.111, 19.643): '8d-4', (29.111, -19.643): '8d-5', (28.0, 47.144): '8e', (26.889, 27.501): '8e-1', (25.778, 47.144): '8e-2', (26.889, 66.787): '8e-3', (29.111, 66.787): '8e-4', (29.111, 27.501): '8e-5', (28.0, 94.288): '8f', (26.889, 74.645): '8f-1', (25.778, 94.288): '8f-2', (26.889, 113.931): '8f-3', (29.111, 113.931): '8f-4', (29.111, 74.645): '8f-5', (28.0, 141.432): '8g', (26.889, 121.789): '8g-1', (25.778, 141.432): '8g-2', (26.889, 161.075): '8g-3', (29.111, 161.075): '8g-4', (29.111, 121.789): '8g-5', (28.0, 188.576): '8h', (26.889, 168.933): '8h-1', (25.778, 188.576): '8h-2', (26.889, 208.219): '8h-3', (29.111, 208.219): '8h-4', (29.111, 168.933): '8h-5', (28.0, 235.72): '8i', (26.889, 216.077): '8i-1', (25.778, 235.72): '8i-2', (26.889, 255.363): '8i-3', (29.111, 255.363): '8i-4', (29.111, 216.077): '8i-5', (28.0, 282.864): '8j', (26.889, 263.221): '8j-1', (25.778, 282.864): '8j-2', (26.889, 302.507): '8j-3', (29.111, 302.507): '8j-4', (29.111, 263.221): '8j-5', (28.0, 330.008): '8k', (26.889, 310.365): '8k-1', (25.778, 330.008): '8k-2', (26.889, 349.651): '8k-3', (29.111, 349.651): '8k-4', (29.111, 310.365): '8k-5', (28.0, 377.152): '8l', (26.889, 357.509): '8l-1', (25.778, 377.152): '8l-2', (26.889, 396.795): '8l-3', (29.111, 396.795): '8l-4', (29.111, 357.509): '8l-5', (28.0, 424.296): '8m', (26.889, 404.653): '8m-1', (25.778, 424.296): '8m-2', (26.889, 443.939): '8m-3', (29.111, 443.939): '8m-4', (29.111, 404.653): '8m-5', (28.0, 471.44): '8n', (26.889, 451.797): '8n-1', (25.778, 471.44): '8n-2', (26.889, 491.083): '8n-3', (29.111, 491.083): '8n-4', (29.111, 451.797): '8n-5', (28.0, 518.584): '8o', (26.889, 498.941): '8o-1', (25.778, 518.584): '8o-2', (26.889, 538.227): '8o-3', (29.111, 538.227): '8o-4', (29.111, 498.941): '8o-5', (28.0, 565.728): '8p', (26.889, 546.085): '8p-1', (25.778, 565.728): '8p-2', (26.889, 585.371): '8p-3', (29.111, 585.371): '8p-4', (29.111, 546.085): '8p-5', (28.0, 612.872): '8q', (26.889, 593.229): '8q-1', (25.778, 612.872): '8q-2', (26.889, 632.515): '8q-3', (29.111, 632.515): '8q-4', (29.111, 593.229): '8q-5', (28.0, 660.016): '8r', (26.889, 640.373): '8r-1', (25.778, 660.016): '8r-2', (26.889, 679.659): '8r-3', (29.111, 679.659): '8r-4', (29.111, 640.373): '8r-5', (28.0, 707.16): '8s', (26.889, 687.517): '8s-1', (25.778, 707.16): '8s-2', (26.889, 726.803): '8s-3', (29.111, 726.803): '8s-4', (29.111, 687.517): '8s-5', (28.0, 754.304): '8t', (26.889, 734.661): '8t-1', (25.778, 754.304): '8t-2', (26.889, 773.947): '8t-3', (29.111, 773.947): '8t-4', (29.111, 734.661): '8t-5', (28.0, 801.448): '8u', (26.889, 781.805): '8u-1', (25.778, 801.448): '8u-2', (29.111, 781.805): '8u-3'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12336dea",
   "metadata": {},
   "outputs": [],
   "source": [
    "#给csv加列\n",
    "Tlist = []\n",
    "Elist = []\n",
    "plot_listx = []\n",
    "plot_listy = []\n",
    "\n",
    "\"\"\"\n",
    "六边形其实是每个正三角形的中心点互相连接形成的\n",
    "下边这个循环的作用是找出每个正三角形的中心点，为下一步连线做准备\n",
    "把tb每8个点分一组，1-8,9-16,17-24,25-32\n",
    "看图可以看出来，每组的第1，3，5，7点都对应正三角形\n",
    "所以根据x mod 8的值，判断tb = x 的时候是不是对应正三角形\n",
    "并且1，3，5，7对应的正三角形的质心情况不一样\n",
    "例：tb = 11，11 mod 8 = 3，这时三角形质心的x是11-1/3，y是从5.893 * 4开始，间隔是5.893 * 8的一组点\n",
    "\n",
    "\"\"\"\n",
    "for x in range(30):\n",
    "    for i in range(-10,20):\n",
    "        xlim = x\n",
    "        if xlim%8 == 1 :\n",
    "            xlim = x  + 1/3\n",
    "            ylim  = 5.893 * 8 * i\n",
    "        elif xlim%8 == 3:\n",
    "            xlim = x -1/3\n",
    "            ylim  = 5.893 * 8 * i + 5.893 * 4 \n",
    "        elif xlim%8 == 5:\n",
    "            xlim = x + 1/3\n",
    "            ylim  = 5.893 * 8 * i + 5.893 * 4\n",
    "        elif xlim%8 == 7 :\n",
    "            xlim = x -1/3\n",
    "            ylim  = 5.893 * 8 * i\n",
    "        else:\n",
    "            continue\n",
    "        plot_listx.append(xlim)\n",
    "        plot_listy.append(ylim)    \n",
    "\n",
    "\"\"\"\n",
    "set是集合，集合里边没有重复元素，这里set(x)等于把x去重\n",
    "\n",
    "c = [f(x) for x in list]是列表推导式\n",
    "等价于\n",
    "c = []\n",
    "for x in list:\n",
    "    c.append(f(x))\n",
    "    \n",
    "c最终是所有三角形的质心列表\n",
    "\"\"\"\n",
    "c = set([(plot_listx[i],plot_listy[i]) for i in range(len(plot_listx))])\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\"\"\"\n",
    "定义一个面类，通过三个维度来表示一个平面，分别是断点span，下限lower，上限upper\n",
    "\n",
    "上下限是一个列表，包含了组成这个平面的直线的斜率、截距\n",
    "例：小区E1-3\n",
    "下限是两条线组成的，分别是y = 0,y = 3*5.893x - 4*5.893,\n",
    "用斜率、截距列表来表示这两条线，就是[0,0],[3*5.893,- 4*5.893]\n",
    "所以lower = [[0,0],[3*5.893,- 4*5.893]]\n",
    "upper只有一条线，y = 5.893x ,为了跟下限对应，当作是两条线，\n",
    "也就是upper = [[5.893,0],[5.893,0]]\n",
    "span是断点（包含端点），两条线的交点的x = 4/3\n",
    "span = [0,4/3,2]\n",
    "通过这三个变量，可以唯一确定一个凸的面，这个图里边的所有小大区都是凸多边形，没问题\n",
    "\"\"\"\n",
    "class Area():\n",
    "    def __init__(self,span,lower,upper):\n",
    "        self.span = span\n",
    "        self.lower = lower\n",
    "        self.upper = upper\n",
    "\n",
    "    def combine(self,another_area):\n",
    "        \"\"\"\n",
    "        拼合两个面的方法，a,b都是Area类，\n",
    "        调用a.combine(b)，会返回一个a,b拼起来的面\n",
    "        \"\"\"\n",
    "        a,b = [self.span,self.lower ,self.upper],[another_area.span,another_area.lower ,another_area.upper]\n",
    "        if a[0][0] > b[0][0]:\n",
    "            a,b = b,a \n",
    "\n",
    "        self.span  =a[0][:-1] + b[0]\n",
    "        self.lower = a[1]+b[1]\n",
    "        self.upper = a[2]+b[2]\n",
    "        return self\n",
    "\n",
    "    def conclude(self,point):\n",
    "        \"\"\"\n",
    "        判断点point = (x,y)是不是包含在这个面内\n",
    "        遍历上下限跟间断点，如果x属于某个区间，y又在上下限内，返回True\n",
    "        \"\"\"\n",
    "        x,y = point\n",
    "        if self.span[0]< x <=self.span[-1]:\n",
    "            for index in range(len(self.span)-1):\n",
    "                left,right = self.span[index],self.span[index+1]\n",
    "                upper,lower = self.upper[index],self.lower[index]\n",
    "                ku,bu = upper\n",
    "                kl,bl = lower\n",
    "                if left < x <= right and kl*x+bl < y <= ku*x + bu :\n",
    "                    return True\n",
    "        return False\n",
    "\n",
    "    def centroid(self,precise = 0):\n",
    "        \"\"\"\n",
    "        用叉积法求面重心\n",
    "        \"\"\"\n",
    "        upper_points = [(self.span[0],self.upper[0][0]*self.span[0] + self.upper[0][1])]\n",
    "        lower_points = [(self.span[0],self.lower[0][0]*self.span[0] + self.lower[0][1])]\n",
    "\n",
    "        for index in range(len(self.span)-1):\n",
    "            upper_points.append((self.span[index+1],self.upper[index][0]*self.span[index+1] + self.upper[index][1]))\n",
    "            lower_points.append((self.span[index+1],self.lower[index][0]*self.span[index+1] + self.lower[index][1]))\n",
    "\n",
    "        points = lower_points + [i for i in reversed(upper_points)]\n",
    "\n",
    "        A = 0.0\n",
    "        point_p = points[-1]\n",
    "        for point in points:\n",
    "            A += (point[1]*point_p[0] - point[0]*point_p[1])\n",
    "            point_p = point\n",
    "        A = abs(A)/2\n",
    "\n",
    "        c_x, c_y = 0.0, 0.0\n",
    "        point_p = points[-1] # point_p 表示前一节点\n",
    "        for point in points:\n",
    "            c_x +=((point[0] + point_p[0]) * (point[1]*point_p[0] - point_p[1]*point[0]))\n",
    "            c_y +=((point[1] + point_p[1]) * (point[1]*point_p[0] - point_p[1]*point[0]))\n",
    "            point_p = point\n",
    "\n",
    "        if precise:\n",
    "            return round(c_x / (6*A),precise),round(c_y / (6*A),precise)\n",
    "        return c_x / (6*A), c_y / (6*A)\n",
    "\n",
    "    def get_apex(self):\n",
    "        \"\"\"\n",
    "        求上下顶点\n",
    "        \"\"\"\n",
    "        ptl = []\n",
    "        ptu = []\n",
    "        for i in range(len(self.lower)):\n",
    "            ptu.append((self.span[i],round(self.upper[i][0]*self.span[i]+self.upper[i][1],3)))\n",
    "            ptl.append((self.span[i],round(self.lower[i][0]*self.span[i]+self.lower[i][1],3)))\n",
    "\n",
    "        ptu.append((self.span[i+1],round(self.upper[i][0]*self.span[i+1]+self.upper[i][1],3)))\n",
    "        ptl.append((self.span[i+1],round(self.lower[i][0]*self.span[i+1]+self.lower[i][1],3)))\n",
    "\n",
    "        return [ptl,ptu]\n",
    "\n",
    "    \n",
    "    \n",
    "\"\"\"\n",
    "求每个区对应的小区、大区，\n",
    "从-2开始，每个区的长度是4\n",
    "\"\"\"\n",
    "for st in [-2,2,6,10,14,18,22,26]:\n",
    "    e = [i for i in c if i[1] >= -5.893*i[0] and st<i[0]<st+4 and i[1]<802]\n",
    "    e.sort(key = lambda x:(x[1],x[0]))\n",
    "    \n",
    "    \"\"\"\n",
    "    每个区里边smallx对应左边的三角形，bigx对应右边的三角形，每个三角形对应三个小区，坐标轴上的单独考虑\n",
    "    \"\"\"\n",
    "    smallx,bigx = st + 2/3,st+4-2/3\n",
    "    \n",
    "    for i in e :\n",
    "        x,y = i\n",
    "        if 1 != 0:\n",
    "            if round(x,5) == round(smallx,5):\n",
    "                \"\"\"\n",
    "                左边的正三角形对应的三个小区\n",
    "                \"\"\"\n",
    "                area1 = Area([st,x],[[3*5.893,y-3*5.893*x]],[[-3*5.893,y+3*5.893*x]]) #E1\n",
    "                area2 = Area([st,x],[[5.893,y-(st+2)*5.893]],[[3*5.893,y-3*5.893*x]]) #E2\n",
    "                area3 = Area([x,st+2],[[5.893,y-(st+2)*5.893]],[[0,y]]) #E2\n",
    "                area4 = Area([st,x],[[-3*5.893,y+3*5.893*x]],[[-5.893,y+(st+2)*5.893]]) #E3\n",
    "                area5 = Area([x,st+2],[[0,y]],[[-5.893,y+(st+2)*5.893]]) #E3\n",
    "\n",
    "                E1,E2,E3 = area1,area2.combine(area3),area4.combine(area5)\n",
    "                Elist.append(E1)\n",
    "                Elist.append(E2)\n",
    "                Elist.append(E3)\n",
    "            elif round(x,5) == round(bigx,5): \n",
    "                \"\"\"\n",
    "                右边的正三角形对应的三个小区\n",
    "                \"\"\"\n",
    "                \n",
    "                area1 = Area([st+2,x],[[-5.893,y+(st+2)*5.893]],[[0,y]]) #E1\n",
    "                area2 = Area([x,st+4],[[-5.893,y+(st+2)*5.893]],[[-3*5.893,y+3*5.893*x]]) #E1\n",
    "                area3 = Area([x,st+4],[[-3*5.893,y+3*5.893*x]],[[3*5.893,y-3*5.893*x]]) #E2\n",
    "                area4 = Area([st+2,x],[[0,y]],[[5.893,y+(st+2)*-5.893]]) #E3\n",
    "                area5 = Area([x,st+4],[[3*5.893,y-3*5.893*x]],[[5.893,y+(st+2)*-5.893]]) #E3  \n",
    "                E1,E2,E3 = area1.combine(area2),area3,area4.combine(area5)\n",
    "                Elist.append(E1)\n",
    "                Elist.append(E2)\n",
    "                Elist.append(E3)\n",
    "            \"\"\"else:\n",
    "            \"\"\"\n",
    "            #遇到坐标轴要拆两半\n",
    "            \"\"\"\n",
    "            if round(x,5) == round(smallx,5):\n",
    "                area0 = Area([st,x],[[3*5.893,y-3*5.893*x]],[[0,0]]) #E1\n",
    "                area1 = Area([st,x],[[0,0]],[[-3*5.893,y+3*5.893*x]]) #E3\n",
    "                area2 = Area([st,x],[[5.893,y-(st+2)*5.893]],[[3*5.893,y-3*5.893*x]]) #E2\n",
    "                area3 = Area([x,st+2],[[5.893,y-(st+2)*5.893]],[[0,y]]) #E2\n",
    "                area4 = Area([st,x],[[-3*5.893,y+3*5.893*x]],[[-5.893,y+(st+2)*5.893]]) #E4\n",
    "                area5 = Area([x,st+2],[[0,y]],[[-5.893,y+(st+2)*5.893]]) #E4\n",
    "\n",
    "                E1,E2,E3,E4 = area0,area2.combine(area3),area1,area4.combine(area5)\n",
    "                Elist.append(E1)\n",
    "                Elist.append(E2)\n",
    "                Elist.append(E3)\n",
    "                Elist.append(E4)\n",
    "            elif round(x,5) == round(bigx,5):  \n",
    "                area1 = Area([st+2,x],[[-5.893,y+(st+2)*5.893]],[[0,y]]) #E1\n",
    "                area2 = Area([x,st+4],[[-5.893,y+(st+2)*5.893]],[[-3*5.893,y+3*5.893*x]]) #E1\n",
    "                area3 = Area([x,st+4],[[-3*5.893,y+3*5.893*x]],[[0,0]]) #E2\n",
    "                area35 = Area([x,st+4],[[0,0]],[[3*5.893,y-3*5.893*x]]) #E4\n",
    "                area4 = Area([st+2,x],[[0,y]],[[5.893,y+(st+2)*-5.893]]) #E3\n",
    "                area5 = Area([x,st+4],[[3*5.893,y-3*5.893*x]],[[5.893,y+(st+2)*-5.893]]) #E3  \n",
    "                E1,E2,E3,E4 = area1.combine(area2),area3,area4.combine(area5),area35\n",
    "                Elist.append(E1)\n",
    "                Elist.append(E2)\n",
    "                Elist.append(E3)\n",
    "                Elist.append(E4)\"\"\"\n",
    "    \n",
    "    y = (st+2) * -5.893 # 这是每个分区里边最下面那个大区最下面那个点的y坐标\n",
    "    while y < 802:\n",
    "        \"\"\"\n",
    "        大区都是固定的，只有涉及坐标轴的时候需要拆开考虑\n",
    "        \"\"\"\n",
    "        \"\"\"if round(y,3) == -5.893 * 4:\n",
    "            \"\"\"\n",
    "            #如果六边形最下面的点y=-5.893 * 4，那这个六边形需要拆成上下两个 #现在不拆了\n",
    "        \"\"\"\n",
    "            area1 = Area([st,st+2,st+4],[[-5.893,y+(st+2)*5.893],[5.893,y-(st+2)*5.893]],[[0,0],[0,0]])\n",
    "            area2 = Area([st,st+2,st+4],[[0,0],[0,0]],[[5.893,y-(st-6)*5.893],[-5.893,y+(st+10)*5.893]])\n",
    "            Tlist.append(area1)\n",
    "            Tlist.append(area2)\"\"\"\n",
    "        area = Area([st,st+2,st+4],[[-5.893,y+(st+2)*5.893],[5.893,y-(st+2)*5.893]],[[5.893,y-(st-6)*5.893],[-5.893,y+(st+10)*5.893]])\n",
    "        Tlist.append(area)\n",
    "        \n",
    "        y += 8*5.893\n",
    "        \n",
    "\n",
    "        \n",
    "\"\"\"\n",
    "下边是根据上面做好的小区、大区列表，用Area类的conclude方法判断点属于哪个区，然后导出csv\n",
    "\"\"\"\n",
    "import os\n",
    "if not os.path.isdir(r\".\\处理后的csv\"):\n",
    "    os.mkdir(r\".\\处理后的csv\")\n",
    "for i in get_file_list(csv_path):\n",
    "    df = pd.read_csv(i)\n",
    "    def get_area(x): \n",
    "        tb,e = x.tb,x.E_sum/1.8099\n",
    "        for area in Elist + Tlist:\n",
    "            if area.conclude((tb,e)):\n",
    "                x,y = area.centroid()\n",
    "                return sign[(round(x,3),round(y,3))]\n",
    "        return \"未知\"\n",
    "    df.loc[:, \"area\"] = df.apply(get_area, axis=1) \n",
    "    df.to_csv(r\".\\处理后的csv\" + \"\\\\\" + i.split(\"\\\\\")[-1],index = False)\n",
    "len(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c265effb",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "for csvpath in pl:\n",
    "    print(csvpath)\n",
    "    record = {}\n",
    "    df = pd.read_csv(csvpath)\n",
    "    \n",
    "    \"\"\"\n",
    "    根据群丛的最大最小E，划定图片的大小，\n",
    "    如果要切，就把cutsign置为True，后边要加白边\n",
    "    \"\"\"\n",
    "    maxy,miny = min(max(df.E_sum)/1.8099,802),max(min(df.E_sum)/1.8099,-190)\n",
    "    maxy,miny = 802,-190\n",
    "    x,y = 5374,14983\n",
    "    if maxy < 188.576:\n",
    "        uplimit = 193\n",
    "        upcutsign = True\n",
    "        anchor = (0.97,0.38)\n",
    "    elif maxy < 330:\n",
    "        uplimit = 332\n",
    "        upcutsign = True\n",
    "        anchor = (0.97,0.50)\n",
    "    elif maxy < 520:\n",
    "        uplimit = 520\n",
    "        upcutsign = True\n",
    "        anchor = (0.97,0.70)\n",
    "    else :\n",
    "        uplimit = 802\n",
    "        upcutsign = False\n",
    "        anchor = (0.97,1)\n",
    "    if miny > -94.288:\n",
    "        downcutsign = True\n",
    "        downlimit = -96\n",
    "    else:\n",
    "        downcutsign = False\n",
    "        downlimit = -190\n",
    "    up_limit = (uplimit + 190)/992\n",
    "    down_limit = (downlimit + 190)/992\n",
    "    \n",
    "    \n",
    "    \"\"\"\n",
    "    图片的初始设置\n",
    "    \"\"\"\n",
    "    pointlist = [(df.tb[i],df.E_sum[i]/1.8099) for i in range(len(df))]\n",
    "    fig= plt.subplots(figsize=(10,32))\n",
    "    ax = plt.gca()\n",
    "    ax.xaxis.set_ticks_position('bottom')\n",
    "    ax.yaxis.set_ticks_position('left')\n",
    "    ax.spines['bottom'].set_position(('data', 0))\n",
    "    ax.spines['left'].set_position(('data', 0))\n",
    "    ax.spines['right'].set_color('none')\n",
    "    ax.spines['top'].set_color('none')\n",
    "    ax.set_xlim(0,30.1)  #设置坐标取值范围\n",
    "    ax.set_ylim(-4*8*5.893,17*8*5.893+0.1)#设置坐标取值范围\n",
    "    ax.xaxis.set_ticks([2,6,10,14,18,22,26,30]) \n",
    "    ax.yaxis.set_ticks([i*8*5.893 for i in range(-4,18)])  \n",
    "    ax.yaxis.set_major_formatter(FormatStrFormatter('%1.3f'))\n",
    "    ax.set_ylabel('E/h',y = 0.19,fontproperties = font_set1)\n",
    "    ax.set_xlabel('TB',fontproperties = font_set1)\n",
    "    ax.xaxis.set_label_coords(0.53,0.18)\n",
    "    \n",
    "    \n",
    "    \n",
    "    \"\"\"\n",
    "    垂线\n",
    "    \"\"\"\n",
    "    for i in [2,6,10,14,18,22,26,30]:\n",
    "        ax.axvline(x=i,ls=\"--\",c = \"grey\",linewidth=1,alpha = 0.5)\n",
    "\n",
    "    \"\"\"\n",
    "    灰色的斜虚线\n",
    "    \"\"\"\n",
    "    for i in range(-10,20):\n",
    "        if i == 0 : continue\n",
    "        ax.plot(np.linspace(0,30,10),5.893*np.linspace(0, 30, 10) + i * 8 * 5.893, '--k',linewidth=1,alpha = 0.5)    \n",
    "        ax.plot(np.linspace(0,30,10),-5.893*np.linspace(0, 30, 10) + i * 8 * 5.893, '--k',linewidth=1,alpha = 0.5)  \n",
    "\n",
    "    \"\"\"\n",
    "    加粗的两条黑斜线\n",
    "    \"\"\"    \n",
    "    ax.plot(np.linspace(0,30,10),5.893*np.linspace(0, 30, 10), linewidth=1.5,color = \"black\")    \n",
    "    ax.plot(np.linspace(0,30,10),-5.893*np.linspace(0, 30, 10), linewidth=1.5,color = \"black\")  \n",
    "\n",
    "\n",
    "    \n",
    "    \"\"\"\n",
    "    按中心点连线\n",
    "    如果tb mod 8 = 1或者5，那就向右画两条一上一下的斜线，如果tb mod 8 = 3或者7，那就向右画一条水平线\n",
    "    \n",
    "    \"\"\"\n",
    "    color = \"black\"\n",
    "    for i in c:\n",
    "        if i[1] < -5.893 * i[0] - 5.893 * 4: continue\n",
    "\n",
    "        if round(i[0],0)%8 == 1:\n",
    "            end1 = [i[0] + 4/3,i[1] + 5.893 * 4 ]\n",
    "            end2 = [i[0] + 4/3,i[1] - 5.893 * 4 ]\n",
    "            ax.plot([i[0],end1[0]],[i[1],end1[1]], linewidth=1,color = color)  \n",
    "            ax.plot([i[0],end2[0]],[i[1],end2[1]], linewidth=1,color = color)  \n",
    "        if round(i[0],0)%8 == 3:\n",
    "            end1 = [i[0] + 8/3,i[1]]\n",
    "\n",
    "            ax.plot([i[0],end1[0]],[i[1],end1[1]], linewidth=1,color = color)  \n",
    "\n",
    "        if round(i[0],0)%8 == 5:\n",
    "            end1 = [i[0] + 4/3,i[1] + 5.893 * 4 ]\n",
    "            end2 = [i[0] + 4/3,i[1] - 5.893 * 4 ]\n",
    "\n",
    "            ax.plot([i[0],end1[0]],[i[1],end1[1]], linewidth=1,color = color)  \n",
    "            ax.plot([i[0],end2[0]],[i[1],end2[1]], linewidth=1,color = color)  \n",
    "\n",
    "        if round(i[0],0)%8 == 7:\n",
    "            end1 = [i[0] + 8/3,i[1]]\n",
    "            ax.plot([i[0],end1[0]],[i[1],end1[1]], linewidth=1,color = color)  \n",
    "\n",
    "    \"\"\"\n",
    "    补上[0，4/3]的短横线\n",
    "    \"\"\"\n",
    "    for i in range(1,17):\n",
    "        ax.plot([0,1+1/3],[i*5.893 * 8,i*5.893 * 8], linewidth=1,color = color)          \n",
    "    \n",
    "    \"\"\"\n",
    "    顶边\n",
    "    \"\"\"\n",
    "    ax.plot([0,30],[136*5.893 ,136*5.893], linewidth=1,color = color)          \n",
    "\n",
    "    混沌态点集合 = []\n",
    "    亚稳态点集合 = []\n",
    "    稳态点集合 = []\n",
    "        \n",
    "    \"\"\"\n",
    "    每个区包含的点数计数\n",
    "    如果遍历到的区刚好在加框线列表里边，就画框线\n",
    "    \"\"\"\n",
    "    countdictE = {}\n",
    "    for index,area in enumerate(Elist):\n",
    "        x,y = area.centroid()\n",
    "        if sign[(round(x,3),round(y,3))] in 加框线的区域:\n",
    "            apexlist = area.get_apex() #返回[[下顶点],[上顶点]]\n",
    "            for idx in range(len(apexlist[0])-1):\n",
    "                upper_apdx_x = [apexlist[1][idx][0],apexlist[1][idx+1][0]]\n",
    "                upper_apdx_y = [apexlist[1][idx][1],apexlist[1][idx+1][1]]\n",
    "                ax.plot(upper_apdx_x,upper_apdx_y,alpha = 1,c=框线颜色,zorder=100)\n",
    "\n",
    "                lower_apdx_x = [apexlist[0][idx][0],apexlist[0][idx+1][0]]\n",
    "                lower_apdx_y = [apexlist[0][idx][1],apexlist[0][idx+1][1]]\n",
    "                ax.plot(lower_apdx_x,lower_apdx_y,alpha = 1,c=框线颜色,zorder=100)\n",
    "\n",
    "\n",
    "            #左右边线\n",
    "            ax.vlines(apexlist[0][0][0],apexlist[0][0][1],apexlist[1][0][1],colors=框线颜色,zorder=100)\n",
    "            ax.vlines(apexlist[0][-1][0],apexlist[0][-1][1],apexlist[1][-1][1],colors=框线颜色,zorder=100)\n",
    "\n",
    "        for point in pointlist:\n",
    "            if area.conclude(point):\n",
    "                if index in countdictE:\n",
    "                    countdictE[index] += 1\n",
    "                else:\n",
    "                    countdictE[index] = 1\n",
    "    \n",
    "    \"\"\"\n",
    "    根据计数转换成百分比，按照百分比分出点的列表\n",
    "    \"\"\"\n",
    "    for i in countdictE:\n",
    "        x,y = Elist[i].centroid()\n",
    "        record[sign[(round(x,3),round(y,3))]] = [countdictE[i],countdictE[i]/len(pointlist)]\n",
    "        if countdictE[i]/len(pointlist) > 0.6321:sig = 0\n",
    "        elif countdictE[i]/len(pointlist) > 0.3679:sig = 1\n",
    "        else:sig = 2\n",
    "        for point in pointlist:\n",
    "            if Elist[i].conclude(point):\n",
    "                if sig == 0:\n",
    "                    稳态点集合.append(point)\n",
    "                elif sig == 1:\n",
    "                    亚稳态点集合.append(point)\n",
    "                else:\n",
    "                    混沌态点集合.append(point)\n",
    "        ax.text(x-0.1,y-1,\"%1.1f\"%(countdictE[i]*100/len(pointlist)) + \"%\",fontproperties = font_set)       \n",
    "        \n",
    "    \"\"\"\n",
    "    同上，只是小区换成了大区\n",
    "    \"\"\"\n",
    "    countdictT = {}\n",
    "    for index,area in enumerate(Tlist):\n",
    "        x,y = area.centroid()\n",
    "        if sign[(round(x,3),round(y,3))] in 加框线的区域:\n",
    "            apexlist = area.get_apex() #返回[[下顶点],[上顶点]]\n",
    "            for idx in range(len(apexlist[0])-1):\n",
    "                upper_apdx_x = [apexlist[1][idx][0],apexlist[1][idx+1][0]]\n",
    "                upper_apdx_y = [apexlist[1][idx][1],apexlist[1][idx+1][1]]\n",
    "                ax.plot(upper_apdx_x,upper_apdx_y,alpha = 1,c=框线颜色,zorder=100)\n",
    "\n",
    "                lower_apdx_x = [apexlist[0][idx][0],apexlist[0][idx+1][0]]\n",
    "                lower_apdx_y = [apexlist[0][idx][1],apexlist[0][idx+1][1]]\n",
    "                ax.plot(lower_apdx_x,lower_apdx_y,alpha = 1,c=框线颜色,zorder=100)\n",
    "\n",
    "            #左右边线\n",
    "            ax.vlines(apexlist[0][0][0],apexlist[0][0][1],apexlist[1][0][1],colors=框线颜色,zorder=100)\n",
    "            ax.vlines(apexlist[0][-1][0],apexlist[0][-1][1],apexlist[1][-1][1],colors=框线颜色,zorder=100)\n",
    "        for point in pointlist:\n",
    "            x,y = area.centroid()\n",
    "            if area.conclude(point):\n",
    "                if index in countdictT:\n",
    "                    countdictT[index] += 1\n",
    "                else:\n",
    "                    countdictT[index] = 1\n",
    "\n",
    "\n",
    "\n",
    "    for i in countdictT:\n",
    "        x,y = Tlist[i].centroid()\n",
    "        #ax.scatter(x,y)\n",
    "        if countdictT[i]/len(pointlist) > 0.6321:sig = 0\n",
    "        elif countdictT[i]/len(pointlist) > 0.3679:sig = 1\n",
    "        else:sig = 2\n",
    "        for point in pointlist:\n",
    "            if Tlist[i].conclude(point):\n",
    "                if sig == 0:\n",
    "                    稳态点集合.append(point)\n",
    "                elif sig == 1:\n",
    "                    亚稳态点集合.append(point)\n",
    "                else:\n",
    "                    混沌态点集合.append(point)\n",
    "        record[sign[(round(x,3),round(y,3))]] = [countdictT[i],countdictT[i]/len(pointlist)]\n",
    "        ax.text(x+0.1,y-1,\"%1.1f\"%(countdictT[i]*100/len(pointlist)) + \"%\",fontproperties = font_set)   \n",
    "\n",
    "    \"\"\"\n",
    "    撒点\n",
    "    \"\"\"\n",
    "    for loca in sign:\n",
    "        ax.text(*loca,sign[loca],fontproperties = font_set)   \n",
    "    \"\"\"if 稳态点集合:        \n",
    "        ax.scatter([i[0] for i in 稳态点集合],[i[1] for i in 稳态点集合],1,\"blue\",label = csvpath.split(\"\\\\\")[-1][:-4] + \"-稳态\")   \n",
    "    if 亚稳态点集合:\n",
    "        ax.scatter([i[0] for i in 亚稳态点集合],[i[1] for i in 亚稳态点集合],1,\"green\",label = csvpath.split(\"\\\\\")[-1][:-4] + \"-亚稳态\")   \n",
    "    if 混沌态点集合:\n",
    "        ax.scatter([i[0] for i in 混沌态点集合],[i[1] for i in 混沌态点集合],1,\"r\",label = csvpath.split(\"\\\\\")[-1][:-4] + \"-混沌态\")\n",
    "    plt.legend(prop = font_set2,bbox_to_anchor=anchor,loc = \"upper right\")\"\"\"\n",
    "    #if 稳态点集合:        \n",
    "        #ax.scatter([i[0] for i in 稳态点集合],[i[1] for i in 稳态点集合],1,\"blue\",label = csvpath.split(\"\\\\\")[-1][:3] + \"-稳态\")   \n",
    "    #if 亚稳态点集合:\n",
    "        #ax.scatter([i[0] for i in 亚稳态点集合],[i[1] for i in 亚稳态点集合],1,\"green\",label = csvpath.split(\"\\\\\")[-1][:3] + \"-亚稳态\")   \n",
    "    #if 混沌态点集合:\n",
    "        #ax.scatter([i[0] for i in 混沌态点集合],[i[1] for i in 混沌态点集合],1,\"r\",label = csvpath.split(\"\\\\\")[-1][:3] + \"-混沌态\")\n",
    "    #plt.legend(prop = font_set2,bbox_to_anchor=anchor,loc = \"upper right\")\n",
    "    #plt.savefig(csvpath.split(\"\\\\\")[-1] + '.png',dpi = 600,bbox_inches='tight')\n",
    "      \n",
    "    from io import BytesIO\n",
    "    from PIL import Image\n",
    "    \n",
    "    #申请缓冲地址\n",
    "    buffer_ = BytesIO()\n",
    "    #保存在内存中\n",
    "    #plt.savefig('123.png',dpi = 600,bbox_inches='tight')\n",
    "    plt.savefig(buffer_,format = 'png',dpi = 600,bbox_inches='tight')\n",
    "    buffer_.seek(0)\n",
    "    img = Image.open(buffer_)\n",
    "    maxy,miny = min(max(df.E_sum)/1.8099,802),max(min(df.E_sum)/1.8099,-190)\n",
    "    x,y = 5374,14983\n",
    "    \n",
    "    \"\"\"\n",
    "    根据开头算的上下位置剪切图片，然后补白边\n",
    "    \"\"\"\n",
    "    region = img.crop((0,y*(1-up_limit),x,y*(1-down_limit)))## 0,0表示要裁剪的位置的左上角坐标，50,50表示右下角。\n",
    "    if upcutsign or downcutsign:\n",
    "        region = add_white_edge(region,upcutsign,downcutsign)\n",
    "    \n",
    "    region.save(csvpath.split(\"\\\\\")[-1][:-4] + '.png') #保存图片\n",
    "\n",
    "    buffer_.close()\n",
    "    \n",
    "    \"\"\"\n",
    "    出csv\n",
    "    \"\"\"\n",
    "    with open(csvpath.split(\"\\\\\")[-1],'w',newline = \"\") as f_c_csv:\n",
    "        writer = csv.writer(f_c_csv)\n",
    "        writer.writerow([\"分区\",\"点数\",\"占比\"])\n",
    "        for i in record:\n",
    "            writer.writerow([\"'%s'\"%i,record[i][0],record[i][1]]) \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03791209",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
